package com.axon.lemon

import grails.converters.JSON
import java.text.DecimalFormat
import java.util.Date;

class IndexController {

	def placeService

	def index() {
		def listPlace = placeService.getListPlace()
		[listPlaces:listPlace]
	}
	def adminPage (){}
	def login (){}
	
	def dologin (){
		try{
			def email	 = params.email
			def pw		 = params.pw
			def usr = UserProfile.findByEmailAndPassword(email,pw)
			if(usr!=null){
				session.user = usr
				session.roleID = "user"
				redirect(action: "index")
			}
			else{
				redirect(action: "login")
			}
		}catch(Exception e){
			render "Fail: "+e.getMessage()
		}finally{
		}
	}
	def signup (){}
	def dosignup (){
		try{
			def fullname = params.fullname
			def email	 = params.email
			def pw		 = params.pw
			def pwcomfirm= params.pwcomfirm

			RoleAcc userrole  = RoleAcc.findByNameRole("user")
			def usr = new UserProfile(email: email, fullName: fullname, gender: "", company: "", website: "", password: pw)
			usr.roleacc=userrole

			if(usr.validate()){
				usr.save()
				session.user=usr
				redirect(action: "index")
			}
			else{
				redirect(action: "signup")
			}
		}catch(Exception e){
			render "Fail: "+e.getMessage()
		}finally{
		}
	}
	def forgotpass (){}
	def updateUser (){}
	def myPlace(){}
	def favouritePage() {}
	def resetpw(){
		def email = params.email
		println(email)
		render email
	}
}